// pages/butorder/butorder.js
const app = getApp();
var utils = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {

	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		//	2. 履约保函     3.预付款保函     4.农民工保函   1.投标保函
		if (app.globalData.type == 2) {
			wx.setNavigationBarTitle({
				title: '履约保函'
			})
		}
		if (app.globalData.type == 3) {
			wx.setNavigationBarTitle({
				title: '预付款保函'
			})
		}
		if (app.globalData.type == 4) {
			wx.setNavigationBarTitle({
				title: '农民工保函'
			})
		}
		if (app.globalData.type == 1) {
			wx.setNavigationBarTitle({
				title: '投标保函'
			})
		}
		this.getLetterDetail();
		this.setData({
			info: wx.getStorageSync("detail")
		})
		console.log(this.data.info)
	},

	//获取保函详情
	getLetterDetail: function (e) {
		var that = this;
		utils.http("/api/v1/common/get_letter_detail", {
			letter_id: wx.getStorageSync("detail").letter_id
		}, function (res) {
			that.setData({
				detail: res.datas
			})
		})
	},
	//支付成功
	formSubmit:function(e){
		var item=wx.getStorageSync("detail");
		utils.http("/api/v1/order/add_order",{
			letter_id:item.letter_id,
			address_id: item.address_id,
			letter_price: item.letter_price,
			letter_date: item.letter_date,
			letter_bank: item.letter_bank,
			letter_company: item.letter_company,
			letter_project: item.letter_project,
			letter_address: item.letter_address,
			letter_files_images: item.letter_files_images,
			letter_files: item.letter_files,
			letter_sn: item.letter_sn,
			letter_project_name: item.letter_project_name,
			letter_toubiaoren: item.letter_toubiaoren,
			letter_shouyiren: item.letter_shouyiren,
			letter_jiafang: item.letter_jiafang
		},function(res){
			if(res.state==1){
				console.log(res.datas)
				wx.reLaunch({
					url: "../ordersuccess/ordersuccess?id=" + res.datas
				})	
			}
		})
		
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})